﻿using System;
//创建时间: 2010-11-4
//创建作者: 李晓忠
//功能说明: CMS系统 内容预览
//修改: 2010-11-4
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using TRPOP.Common;
using TRPOP.CMS.Web.UI;


using TRPOP.CMS.Business;
using TRPOP.CMS.Model;
using Newtonsoft.Json;
using System.Data;
using System.Text;

namespace TRPOP.CMS.Web.Admin
{
    public partial class content_view : BaseAdmin
    {
        #region 当前页面权限验证
        protected override void SubPageInit()
        {
            base.m_SubPagePermission = Plugin.PermissionKeys.PermissionEnum.Content_AllControl;
        }
        #endregion


        #region 页面变量
        protected int m_intNId = 0;
        protected int m_intId = 0;
        protected string m_strAction = "";
        protected string strHtml = "";
        #endregion

        #region 页面事件
        protected void Page_Load(object sender, EventArgs e)
        {
            m_intNId = RequestHelper.RequestInt("nodeid");
            m_strAction = RequestHelper.RequestString("ac");
            m_intId = RequestHelper.RequestInt("id");
            if (!IsPostBack)
            {
                LoadBase();
                BindData();
            }
        }

        #endregion

        #region 页面方法

        public void LoadBase()
        {

        }

        public void BindData()
        {
            if (m_intId > 0)//&&m_intNId > 0
            {
                string strTempTemplate = ltInfoTemplate.Text;
                StringBuilder strBuild = new StringBuilder();

                ContentInfo mContentInfo = (new ContentManage()).GetInfoById(m_intId);
                if (mContentInfo != null)
                {
                    string strShowVal = "";
                    #region  模型信息
                    DataSet ds = (new ContentManage()).GetDataSet(mContentInfo.ExtendTableName, "", " and " + mContentInfo.ExtendTableName + "id=" + mContentInfo.ExtendId, "");
                    List<ModelFieldInfoWithTableName> listModelFieldInfo = (new ModelFieldManage()).GetWithTableNameListByNodeId(mContentInfo.NodeId);
                    if (listModelFieldInfo == null)
                        return;
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        DataRow dr = ds.Tables[0].Rows[0];

                        foreach (ModelFieldInfoWithTableName info in listModelFieldInfo)
                        {
                            FormInputTypeInfo oFormInputTypeInfo = (new FormInputTypeManage()).GetInfoByIdFromCache(info.FormInputTypeId);
                            if (oFormInputTypeInfo != null)
                            {
                                strShowVal = dr[info.FieldName].ToString();
                                switch (oFormInputTypeInfo.FormItem)
                                {
                                    case "radio":
                                        break;
                                    case "select":
                                        #region 邦数据
                                        //if(info.FormInputValueTypeId)
                                        FormInputValueTypeInfo mFormInputValueTypeInfo = (new FormInputValueTypeManage()).GetInfoById(info.FormInputValueTypeId);
                                        if (mFormInputValueTypeInfo != null)
                                        {
                                            if (mFormInputValueTypeInfo.Step == 1)
                                            {
                                                #region 单级邦定
                                                if (strShowVal != "")
                                                {
                                                    FormInputValueInfo mFormInputValueInfo = (new FormInputValueManage()).GetInfoById(Convert.ToInt32(strShowVal));
                                                    if (mFormInputValueInfo != null)
                                                    {
                                                        strShowVal = mFormInputValueInfo.Name;
                                                    }
                                                }
                                                #endregion
                                            }
                                            else if (mFormInputValueTypeInfo.Step > 1)
                                            {
                                                #region 多级邦定
                                                if (strShowVal != "")
                                                {
                                                    strShowVal = (new FormInputValueManage()).GetValueNameByIDs(strShowVal);
                                                }
                                                #endregion
                                            }
                                        }
                                        #endregion
                                        break;
                                    case "ckeditor":
                                        break;
                                    default:
                                        break;
                                }
                            }
                            strBuild.Append(string.Format(strTempTemplate, info.Name, strShowVal));
                        }

                    }
                    #endregion

                    #region 基表信息
                    strBuild.Append(string.Format(strTempTemplate, "发布时间", mContentInfo.PubTime));
                    strBuild.Append(string.Format(strTempTemplate, "创建日期", mContentInfo.AddTime));
                    strBuild.Append(string.Format(strTempTemplate, "上次修改日期", mContentInfo.UpdateTime));
                    strBuild.Append(string.Format(strTempTemplate, "创建用户", GetAdminNameById(mContentInfo.AddUserId)));
                    strBuild.Append(string.Format(strTempTemplate, "上次修改用户", GetAdminNameById(mContentInfo.UpdateUserId)));
                    #endregion

                    ltInfoTemplate.Text = strBuild.ToString();
                }

            }
            else
            {
                ltInfoTemplate.Text = "";
            }

        }


        #endregion
    }
}
